// pages/setting/setting.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //模式，顺序：order，随机：random
    mode: null,
    //级别，难度低：low，难度高：high
    level: null
  },

  toCiku: function() {
    wx.navigateTo({
      url: '../ciku/ciku'
    })
  },

  setMode: function(event) {
    var mode = event.currentTarget.dataset.mode;
    this.setData({
      mode: mode
    })
    wx.setStorageSync('mode', mode);
    wx.setStorageSync('settingChangeCache', true);
  },

  setLevel: function(event) {
    var level = event.currentTarget.dataset.level;
    this.setData({
      level: level
    })
    wx.setStorageSync('level', level);
    wx.setStorageSync('settingChangeCache', true);
  },

  beauty: function() {
    var beautyList = wx.getStorageSync('beautyList');
    if(beautyList == null || beautyList.length <= 0){
      wx.showToast({
        title: "暂无数据",
        duration: 1500,
        icon: "none"
      });
      return;
    }
    wx.previewImage({
      urls: beautyList
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    //查难度设置缓存和顺序设置缓存，如果没有的话，默认设置简单，随机背单词
    var mode = wx.getStorageSync('mode');
    if(mode == null || mode == ''){
      this.setData({
        mode: "random"
      })
      wx.setStorageSync('mode', "random");
    }else{
      this.setData({
        mode: mode
      })
    }
    var level = wx.getStorageSync('level');
    if(level == null || level == ''){
      this.setData({
        level: "low"
      })
      wx.setStorageSync('level', "low");
    }else{
      this.setData({
        level: level
      })
    }
  },

  onShareAppMessage(res) {
    if(res.from === "button"){
      //来自页面内的转发按钮
      console.log("来自页面内的转发按钮");
    }else if(res.from === "menu"){
      //来自右上角菜单的转发按钮
      console.log("来自右上角菜单的转发按钮");
    }
    return {
      title: "背单词，看妹子",
      imageUrl: "../../images/resources/share.png",
      path: "/pages/index/index"
    }  
  },

  sang: function() {
    //赞赏
    wx.previewImage({
      urls: ['https://cuntujun-bucket.oss-cn-shanghai.aliyuncs.com/static/charmword/charm-sang.png']
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})